<!DOCTYPE html>
<html lang="zh" xmlns:th="https://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('友链列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
</head>

<body class="gray-bg">
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 友链概览
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新列表"><i
                            class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <ul class="folder-list m-b-md linksDetails" style="padding: 0">
                    <li class="condition" onclick="$.table.search()">
                        <a> <i class="fa fa-inbox "></i> 所有友链
                            <span class="label label-success pull-right"
                                  th:text="${map['total']}">123 </span>
                        </a>
                    </li>
                    <li class="link_available" val="1">
                        <a> <i class="fa fa-tags "></i> 死链
                            <span class="label  label-default  pull-right"
                                  th:text="${map['die']}">123</span>
                        </a>
                    </li>
                    <li class="link_processed" val="0">
                        <a> <i class="fa fa-chain-broken "></i> 未处理友链
                            <span class="label label-warning pull-right " th:text="${map['unhandled']}">123</span>
                        </a>
                    </li>
                    <li class=" link_display" val="0">
                        <a> <i class="fa fa-indent "></i> 已隐藏友链
                            <span class="label label-danger  pull-right "
                                  th:text="${map['hide']}"> 123</span>
                        </a>
                    </li>
                    <li class=" link_display" val="1">
                        <a> <i class="fa fa-indent "></i> 已显示友链
                            <span class="label label-danger  pull-right "
                                  th:text="${map['display']}"> 123</span>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="link-form">
                <input type="hidden" name="available" id="link_available">
                <input type="hidden" name="display" id="link_display">
                <input type="hidden" name="processed" id="link_processed">
                <div class="select-list">
                    <ul>
                        <li>
                            友链名称：：<input type="text" name="title"/>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i> 搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i> 重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="createMenuItem('/link/link/add','新增友链')">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary btn-edit single disabled" onclick="$.operate.editTab()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-trash"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<script th:inline="javascript">
    var available = [[${@dict.getType('link_link_available')}]];
    var display = [[${@dict.getType('link_link_display')}]];
    var prefix = ctx + "link/link";

    function changeDisplay(status) {
        var data = {"linkId": $.table.getSelectIds()};
        $.operate.put($.table._option.changeStatusUrl + "/" + status, data);
    }

    function changeSupport(support) {
        var data = {"blogIds": $.table.getSelectIds()};
        $.operate.put($.table._option.changeSupportUrl + "/" + status, data);
    }

    $(".link_display").click(function () {
        $.form.reset("link-form");
        $("#link_display").val($(this).attr("val"));
        $.table.search();
    });

    $(".link_available").click(function () {
        $.form.reset("link-form");
        $("#link_available").val($(this).attr("val"))
        $.table.search();
    });

    $(".link_processed").click(function () {
        $.form.reset("link-form");
        $("#link_processed").val($(this).attr("val"))
        $.table.search();
    });

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            changeDisplayUrl: prefix + "/display",
            sortName: "createTime",
            sortOrder: "desc",
            uniqueId: "linkId",
            modalName: "友链",
            columns: [{
                field: 'state',
                checkbox: true
            }, {
                field: 'linkId',
                title: '友链ID'
            }, {
                field: 'title',
                title: '名称',
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            }, {
                field: 'description',
                title: '描述',
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            }, {
                field: 'available',
                title: '状态',
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(available, value);
                }
            }, {
                field: 'display',
                title: '显示',
                align: 'center',
                formatter: function (value, row, index) {
                    return statusTools(value, row);
                }
            }, {
                field: 'weight',
                title: '权重',
                align: 'center',
                sortable: true
            }, {
                field: 'click',
                title: '点击量',
                sortable: true
            }, {
                field: 'createTime',
                title: '创建时间',
                sortable: true
            }, {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    if (row.processed == 1) {
                        actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.linkId + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.linkId + '\')"><i class="fa fa-remove"></i> 删除</a> ');
                    } else if (row.processed == 0) {
                        actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.linkId + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="processed(' + row.linkId + ')"><i class="fa fa-key"></i> 通过</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.linkId + '\')"><i class="fa fa-trash"></i> 拒绝</a> ');
                    } else {
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.linkId + '\')"><i class="fa fa-remove"></i> 删除</a> ');
                    }
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });

    function processed(id) {
        $.operate.put("/link/link/processed", {"ids": id});
    }

    function statusTools(value, row) {
        if (value == "0") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.linkId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.linkId + '\')"></i> ';
        }
    }

    /* -停用 */
    function disable(linkId) {
        $.modal.confirm("确认要取消显示该友链吗？", function () {
            $.operate.put($.table._option.changeDisplayUrl + "/0", {"id": linkId});
        })
    }

    /* -启用 */
    function enable(linkId) {
        $.modal.confirm("确认要显示该友链吗？", function () {
            $.operate.put($.table._option.changeDisplayUrl + "/1", {"id": linkId});
        })
    }
</script>
</body>

</html>